<?php
/**
 * @Author: Xu Liu email:2867557054@qq.com
 * @Date:   2016-12-15 13:31:33
 * @Last Modified by:   Xu Liu
 * @Last Modified time: 2018-02-24 15:32:12
 */
if (!defined('IN_DISCUZ')) {
    exit('Access Denied');
}
global $_G;
if (FORMHASH != trim($_GET['formhash'])) {
    echo 'error';
    exit;
}
require_once libfile('function/jameson', 'plugin/jameson_read');
init_jameson();
$optype = trim($_GET['optype']);
switch ($optype) {
    case 'changecategory':
        $parent_id = intval($_GET['parent_id']);
        $categorys = C::t('#jameson_read#jamesonread_categorys')->fetch_all_parent($parent_id);
        if (!is_array($categorys)) {
            echo 'error';
        } else {
            $str = '';
            foreach ($categorys as $key => $value) {
                $str .= '<option value="' . $value['category_id'] . '">' . $value['category_name'] . '</option>';
            }
            echo $str;
        }
        break;
    case 'changecolum':
        $data            = $datatid            = array();
        $colum_id        = intval($_GET['colum_id']);
        $tid             = intval($_GET['tid']);
        $data['subject'] = $datatid['subject'] = daddslashes(trim($_GET['subject']));
        $data['j_id']    = intval($_GET['j_id']);
        $data['zhangjie']    = intval($_GET['zhangjie']);
        if (strtolower($_G['charset']) == 'gbk' && xfxs_isutf($data['subject'])) {
            $data['subject'] = diconv($data['subject'], 'utf-8', 'gbk');
        } else if (strtolower($_G['charset']) == 'utf-8' && !xfxs_isutf($data['subject'])) {
            $data['subject'] = diconv($data['subject'], "GB2312", 'utf-8');
        }
        $authorinfo = C::t('#jameson_read#jamesonread_authors')->fetch($_G['uid']);
        if ($authorinfo[$authorinfo['setsj']]) {
            $price = intval($_GET['price']);
            if ($authorinfo['setsj'] == 'zgsj') {
                $price = $price > $authorinfo['zgsj'] ? $authorinfo['zgsj'] : $price;
            }
            $data['price'] = $datatid['price'] = $price;
        }
        if (C::t('#jameson_read#jamesonread_colums')->update($colum_id, $data)) {
            C::t('forum_thread')->update($tid, $datatid);
            $book_id = DB::result_first('SELECT book_id FROM %t WHERE tid=%d', array('jamesonread_colums', $tid));
            C::t("#jameson_read#jamesonread_books")->clear_cache(array('bookinfo-'.$book_id . '-0', 'bookinfo-'.$book_id . '-' . $_G['uid']));
            echo 'success';
        } else {
            echo 'error';
        }
        break;
    case 'selectcolum':
        $book_id = intval($_GET['book_id']);
        $j_id    = intval($_GET['j_id']);
        $start   = (intval($_GET['currentpage']) - 1) * 30;
        if (!$book_id || !$j_id) {
            echo 'error';
            exit;
        }
        $authorinfo = C::t('#jameson_read#jamesonread_authors')->fetch($_G['uid']);
        $fenjuan    = (array) DB::fetch_all('SELECT * FROM %t WHERE book_id=%d ORDER BY order_num ASC', array('jamesonread_fenjuan', $book_id), 'j_id');
        $nofor      = DB::fetch_all('SELECT * FROM %t WHERE ' . DB::field('j_id', $j_id) . ' ORDER BY j_id, zhangjie ASC LIMIT %d,%d', array('jamesonread_colums', $start, 30));
        $html       = '';
        foreach ($nofor as $key => $colum) {
            $html .= '<tr data-cid="' . $colum['colum_id'] . '" id="colums_tr_' . $colum['colum_id'] . '">
                    <td class="subjectinput">
                        <span class="pipe">' . lang('plugin/jameson_read', 'biaoti') . '</span>
                        <input class="uk-input uk-input-75per" uk-tooltip title="' . lang('plugin/jameson_read', 'dianjikongbaixiugai') . '"  required type="text" onchange="jameson.changeColum(' . $colum['colum_id'] . ',' . $colum['tid'] . ')" id="subject_' . $colum['colum_id'] . '" value="' . $colum['subject'] . '"  />
                    </td>
                    <td class="">';

            if ($authorinfo[$authorinfo['setsj']] > 0) {
                $html .= '<span class="pipe">' . lang('plugin/jameson_read', 'shoujia') . '</span>';
                if ($authorinfo['setsj'] == 'qzsj') {
                    $html .= '<select id="price_' . $colum['colum_id'] . '"  class="uk-select uk-input-65px" data-zgsj="' . $authorinfo['zgsj'] . '" onchange="jameson.changeColum(' . $colum['colum_id'] . ',' . $colum['tid'] . ')" data-zgsj="' . $authorinfo['zgsj'] . '">
                                    <option' . ($colum['price'] < 1 ? 'selected' : '') . 'value="0">0</option>
                                    <option ' . ($colum['price'] ? 'selected' : '') . ' value="' . $authorinfo['qzsj'] . '">' . $authorinfo['qzsj'] . '</option>
                                </select>';
                } else {
                    $html .= '<input uk-tooltip title="&lt;' . $authorinfo['zgsj'] . $_G['jameson_read']['trametitle'] . '" placeholder="&lt;' . $authorinfo['zgsj'] . $_G['jameson_read']['trametitle'] . '" class="uk-input uk-input-45px movingnone"  onchange="jameson.changeColum(' . $colum['colum_id'] . ',' . $colum['tid'] . ')" data-zgsj="' . $authorinfo['zgsj'] . '" type="text"   id="price_' . $colum['colum_id'] . '" value="' . $colum['price'] . '" />';
                }
                $html .= '<span class="xg1">' . $_G['jameson_read']['trametitle'] . '</span>';
            }
            $html .= '</td>
                    <td class="uk-text-right">
                        <select id="jtitle_' . $colum['colum_id'] . '"  class="uk-select uk-input-65px" onchange="jameson.changeColum(' . $colum['colum_id'] . ',' . $colum['tid'] . ')">';
            foreach ($fenjuan as $jtemp) {
                $html .= '
                            <option  ' . ($jtemp['j_id'] == $colum['j_id'] ? 'selected' : '') . ' value="' . $jtemp['j_id'] . '">' . $jtemp['j_title'] . '</option>';
            }
            $html .= '</select>';
            if ($authorinfo['allowedit']) {
                $html .= '<a href="./plugin.php?id=jameson_read&contrl=author&act=edit&tid=' . $colum['tid'] . '&pid=' . $colum['pid'] . '&book_id=' . $colum['book_id'] . '" target="_blank" class=" movingnone xs1">' . lang('plugin/jameson_read', 'bianjizhengwen') . '</a>';
            }
            $html .= '<a href="' . jamesonurl('thread', $colum['tid'], $colum['pid']) . '" class=" movingnone xs1">' . lang('plugin/jameson_read', 'yulan') . '</a>';
            if ($authorinfo['allowedit']) {
                $html .= '<a href="javascript:;" onclick="jameson.remove(this,\'colums\',' . $colum['colum_id'] . ')" class=" movingnone xs1">' . lang('plugin/jameson_read', 'shanchu') . '</a>';
            }
            $html .= '</td></tr>';
        }
        echo $html;
        break;
    case 'ishasbuy':
        $book_id = intval($_GET['book_id']);
        $tids    = DB::fetch_all('SELECT tid FROM %t WHERE book_id=%d AND buy_id=%d', array('jamesonread_buytids', $book_id, $_G['uid']));
        $tidstr  = '';
        if ($tids) {
            foreach ($tids as $key => $value) {
                $tidstr .= $value['tid'] . ',';
            }
            echo trim($tidstr, ',');
        } else {
            echo 'error';
        }
        break;
    case 'changejuan':
        if (!$_GET['j_id'] || !$_GET['j_title']) {
            echo 'error2';
        } else {
            $jtitle = urldecode($_GET['j_title']);
            if (strtolower($_G['charset']) == 'gbk' && xfxs_isutf($jtitle)) {
                $jtitle = diconv($jtitle, 'utf-8', 'gbk');
            } else if (strtolower($_G['charset']) == 'utf-8' && !xfxs_isutf($jtitle)) {
                $jtitle = diconv($jtitle, "GB2312", 'utf-8');
            }
            C::t('#jameson_read#jamesonread_fenjuan')->update($_GET['j_id'], array('j_title' => daddslashes($jtitle), 'order_num' => intval($_GET['order_num'])));
            $book_id = DB::result_first('SELECT book_id FROM %t WHERE j_id=%d', array('jamesonread_fenjuan', $_GET['j_id']));
            C::t("#jameson_read#jamesonread_books")->clear_cache(array('bookinfo-'.$book_id . '-0', 'bookinfo-'.$book_id . '-' . $_G['uid']));
            echo 'success';
        }
        break;
    case 'remove':
        if ($_G['uid'] && (($_G['uid'] == 1) || ($_G['uid'] == DB::result_first('SELECT uid FROM %t WHERE book_id=%d', array('jamesonread_books', $_GET['book_id']))))) {
            $id   = intval($_GET['did']);
            $type = daddslashes(trim($_GET['type']));
            switch ($type) {
                case 'colums':
                    jamesonread_deletecolum($id);
                    echo 'success';
                    break;
                case 'fenjuan':
                    jamesonread_deletefenjuan($id);
                    echo 'success';
                    break;
                case 'books':
                    echo 'success';
                    jamesonread_deletebook($id);
                    break;
                case 'pdf':
                    echo 'success';
                    jamesonread_deletepdf($id);
                    break;
            }
        } else {
            echo 'error';
        }
        break;
    case 'scoreaction':
        $book_id = intval($_GET['book_id']);
        $score   = 2 * intval($_GET['score']);
        if ($has = C::t('#jameson_read#jamesonread_scores')->fetchScore($_G['uid'], $book_id)) {
            $bookinfo  = C::t('#jameson_read#jamesonread_books')->fetch($book_id);
            $newscores = $bookinfo['scores'] - $has['score'] + $score;
            $newscores = $newscores > 0 ? $newscores : 0;
            C::t('#jameson_read#jamesonread_books')->update($book_id, array('scores' => $newscores));
            C::t('#jameson_read#jamesonread_scores')->update($has['score_id'], array('score' => $score));
            echo 'success';
            break;
        } else {
            $data            = array();
            $data['book_id'] = $book_id;
            $data['uid']     = intval($_G['uid']);
            $data['score']   = $score;
            $data['addtime'] = TIMESTAMP;
            if (C::t('#jameson_read#jamesonread_scores')->insertAndBooks($data)) {
                C::t("#jameson_read#jamesonread_books")->clear_cache(array('bookinfo-'.$book_id . '-0', 'bookinfo-'.$book_id . '-' . $_G['uid']));
                echo 'success';
            } else {
                echo 'error';
            }
        }
        break;
    case 'postshuping':
        $data            = array();
        $data['book_id'] = intval($_GET['book_id']);
        $dp_id           = intval($_GET['dp_id']);
        if (C::t('#jameson_read#jamesonread_dianping')->hasshuping($_G['uid'], $data['book_id'], intval($_G['jameson_read']['dianpingnums']))) {
            echo 'hasshuping';
        } else {
            $text = daddslashes($_GET['text']);
            if (strtolower($_G['charset']) == 'gbk' && xfxs_isutf($text)) {
                $text = diconv($text, 'utf-8', 'gbk');
            } else if (strtolower($_G['charset']) == 'utf-8' && !xfxs_isutf($text)) {
                $text = diconv($text, "GB2312", 'utf-8');
            }
            $data['text']    = cutstr($text, $_G['jameson_read']['shupinglength'], '');
            $data['uid']     = intval($_G['uid']);
            $data['addtime'] = TIMESTAMP;
            if ($dp_id) {
                $old = DB::result_first('SELECT yinyongtext FROM %t WHERE dp_id=%d', array('jamesonread_dianping', $dp_id));
                C::t('#jameson_read#jamesonread_dianping')->update($dp_id, array(
                    'yinyongtext' => ($old ? $old . '.......' . $data['text'] : $data['text']) . '<span>' . $_G['username'] . ' | ' . dgmdate(TIMESTAMP) . '</span>',
                ));
            } else {
                C::t('#jameson_read#jamesonread_dianping')->insert($data, true);
            }
            echo 'success';
        }
        break;
    case 'loadmore':
        $book_id = intval($_GET['book_id']);
        $start   = intval($_GET['curpage']) * 10;
        $data    = C::t('#jameson_read#jamesonread_dianping')->fetch_new($book_id, $start);
        $html    = '';
        foreach ($data as $key => $value) {
            $yinyongtext = '';
            if ($value['yinyongtext']) {
                $yins = explode('.......', stripcslashes(trim($value['yinyongtext'])));
                foreach ($yins as $yt) {
                    $yinyongtext .= '<blockquote>' . $yt . '</blockquote>';
                }
            }
            $html .= '
                <article class="uk-comment shupingcontent uk-padding-small" id="dianping_tr_' . $value['dp_id'] . '">
                    <div class="uk-comment-body uk-padding-remove">
                        <div class="uk-grid-collapse" uk-grid>
                            <div class="uk-width-small uk-text-center" style="width: 80px;">
                                <div class="uk-margin-small">
                                    <img class="uk-comment-avatar uk-border-circle" src="' . avatar($value['uid'], 'middle', true) . '" width="48" height="48">
                                </div>
                                <a class="uk-link-reset" href="./home.php?mod=space&uid=' . $value['uid'] . '">' . $value['author'] . '</a>
                            </div>
                            <div class="uk-width-expand">
                                <ul class="uk-comment-meta uk-subnav uk-margin-remove uk-padding-remove xs12">
                                    <li class="uk-padding-remove"><a>' . dgmdate($value['addtime']) . '</a></li>
                                </ul>
                                <div data-id="onlycontent" class="mt8">
                                    <p data-only="1">' . nl2br(dhtmlspecialchars($value['text'])) . '</p>
                                    ' . $yinyongtext . '
                                </div>
                                <ul class="uk-comment-meta uk-subnav  uk-margin-remove uk-padding-remove xs12">
                                    <li class="uk-padding-remove">
                                        <a class="" href="javascript:;" onclick="jameson.replyshuping(this,' . $value['dp_id'] . ')">' . lang('plugin/jameson_read', 'huifu') . '</a>
                                    </li>
                                    <li class="uk-padding-remove">
                                        <a href="javascript:;" onclick="jameson.zanorfandui(' . $value['dp_id'] . ',\'zhichi\',this)" class="' . (getcookie('biaotai_' . $value['dp_id']) == 'zhichi' ? "uk-text-danger" : "") . '">' . lang("plugin/jameson_read", "zancheng") . '[<span class="num">' . $value['zhichi'] . '</span>]</a>
                                    </li>
                                    <li class="uk-padding-remove">
                                        <a href="javascript:;" onclick="jameson.zanorfandui(' . $value['dp_id'] . ',\'fandui\',this)" class="' . (getcookie('biaotai_' . $value['dp_id']) == 'fandui' ? "uk-text-danger" : "") . '">' . lang("plugin/jameson_read", "zancheng") . '[<span class="num">' . $value['fandui'] . '</span>]</a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </article>
            ';
        }
        echo $html;
        break;
    case 'biaotai':
        $dp_id = intval($_GET['dp_id']);
        $type  = daddslashes($_GET['type']);
        if (C::t('#jameson_read#jamesonread_dianping')->addBiaotai($dp_id, $type)) {
            echo 'success';
        } else {
            echo 'error';
        }
        break;
    case 'favoreaction':
        $data           = array();
        $data['uid']    = intval($_G['uid']);
        $data['status'] = 1;
        if (isset($_GET['piliang'])) {
            $bookids = explode(',', $_GET['piliang']);
            foreach ($bookids as $key => $value) {
                $data['book_id'] = intval($value);
                C::t('#jameson_read#jamesonread_favores')->insertAndBooks($data);
            }
            exit;
        } else {
            $data['book_id'] = intval($_GET['book_id']);
        }
        if (C::t('#jameson_read#jamesonread_favores')->hasFavore($data['uid'], $data['book_id'])) {
            echo 'hasfavore';
        } else {
            if (C::t('#jameson_read#jamesonread_favores')->insertAndBooks($data)) {
                @unlink('./data/cache/jamesonreadindexbook_' . $data['book_id'] . '_' . $_G['jameson_read']['template'] . '_' . $_G['uid'] . '.html');
                echo 'success';
            } else {
                echo 'sqlerror';
            }
        }
        break;
    case 'dashang':
        $num = intval($_GET['num']);
        if (!$_G['uid'] || $num < 1) {
            echo 'error';
            break;
        }
        $trameid = $_G['jameson_read']['dstrameid'];
        $book_id = intval($_GET['book_id']);
        if (!$book_id) {
            echo 'error';
            break;
        }
        $bookinfo  = C::t('#jameson_read#jamesonread_books')->fetch($book_id);
        $tid       = $_GET['btid'] ? intval($_GET['btid']) : 0;
        $pid       = $_GET['pid'] ? intval($_GET['pid']) : 0;
        $yongjinbi = $_G['jameson_read']['dsyongjin'];
        $dyongjin  = floor($num * ($yongjinbi / 100));
        if ($num > $_G['jameson_read']['dstramenum']) {
            echo 'buzu';
            exit;
        }
        $res1 = updatemembercount($_G['uid'], array($trameid => -$num), true, 'jds', 0, lang('plugin/jameson_read', 'dashangtushufeiyong'), lang('plugin/jameson_read', 'dashangtushufeiyong'));
        $res2 = updatemembercount(1, array($trameid => $dyongjin), true, 'Y_J', 0, lang('plugin/jameson_read', 'xiaoshouyongjin'), lang('plugin/jameson_read', 'xiaoshouyongjin'));
        if($dyongjin>0){
            $res3 = updatemembercount($bookinfo['uid'], array($trameid => $num - $dyongjin), true, 'jbd', 0, lang('plugin/jameson_read', 'beidashangtushufeiyong'), lang('plugin/jameson_read', 'beidashangtushufeiyong'));
        }
        if (!$res1 && !$res2) {
            C::t('#jameson_read#jamesonread_dashang')->insert(array(
                'uid'      => $_G['uid'],
                'authorid' => $bookinfo['uid'],
                'addtime'  => TIMESTAMP,
                'price'    => $num,
                'book_id'  => $book_id,
                'tid'      => $tid,
                'pid'      => $pid,
                'username' => $_G['username'],
            ));
            C::t('#jameson_read#jamesonread_yongjin')->insert(array(
                'buy_id'    => $_G['uid'],
                'author_id' => $bookinfo['uid'],
                'book_id'   => $book_id,
                'saleprice' => $num,
                'yongjinbi' => $yongjinbi,
                'yongjin'   => $dyongjin,
                'addtime'   => TIMESTAMP,
                'type'      => 2,
            ));

            $sendauthor = '<a href="./home.php?mod=space&uid='
            . $_G['uid']
            . '">'
            . $_G['member']['username']
            . '</a>'
            . lang('plugin/jameson_read', 'dashangletushu')
            . '<a href="'
            . ($_G['cache']['plugin']['jameson_read']['rewurl'] ? jamesonurl('book', $book_id) : './plugin.php?id=jameson_read&contrl=index&act=book&book_id=' . $book_id)
            . '">['
            . $bookinfo['book_name']
            . ']</a>,'
            . lang('plugin/jameson_read', 'kouchuyongjinhoushouru')
                . ($num - $dyongjin)
                . $_G['jameson_read']['dstrametitle'];

            $sendbuy =
            lang('plugin/jameson_read', 'dashangletushu')
            . '<a href="'
            . ($_G['cache']['plugin']['jameson_read']['rewurl'] ? jamesonurl('book', $book_id) : './plugin.php?id=jameson_read&contrl=index&act=book&book_id=' . $book_id)
            . '">['
            . $bookinfo['book_name']
            . ']</a>,'
            . lang('plugin/jameson_read', 'yikouchu')
                . $num
                . $_G['jameson_read']['dstrametitle'];
            // 向作者发送消息
            jameson_sendsms($bookinfo['uid'], 0, '', $sendauthor, $book_id);
            // 向打赏者发送消息
            jameson_sendsms($_G['uid'], 0, '', $sendbuy, $book_id);
            C::t("#jameson_read#jamesonread_books")->clear_cache(array('bookinfo-'.$book_id . '-0', 'bookinfo-'.$book_id . '-' . $_G['uid']));
            C::t("#jameson_read#jamesonread_dashang")->clear_cache(array('dashang-count', 'dashang-dashang'));
            echo 'success';
        } else {
            echo 'error';
        }
        break;
    case 'addbookmark':
        $data            = array();
        $data['book_id'] = intval($_GET['book_id']);
        $data['tid']     = intval($_GET['tid']);
        if (!$data['book_id'] || !$data['tid']) {
            echo 0;
            break;
        }
        if (C::t('#jameson_read#jamesonread_bookmarks')->hasMark($data['tid'], $_G['uid']) < 1) {
            $data['addtime'] = TIMESTAMP;
            $data['uid']     = $_G['uid'];
            if ($id = C::t('#jameson_read#jamesonread_bookmarks')->insert($data, true)) {
                C::t("#jameson_read#jamesonread_books")->clear_cache(array("bookinfo-".$data['book_id'] . '-0', "bookinfo-".$data['book_id'] . '-' . $_G['uid']));
                echo $id;
            } else {
                echo 'error';
            }
        }
        break;
    case 'delmark':
        $pkid = intval($_GET['pkid']);
        if (!$pkid) {
            echo 'error';
        }
        C::t('#jameson_read#jamesonread_bookmarks')->delete($pkid);
        echo 'success';
        break;
    case "delstorebook":
        $uid = intval($_G['uid']);
        if (!$uid) {
            echo 'error';
            break;
        }
        $book_id = explode(',', trim($_GET['book_id'], ','));
        foreach ($book_id as $key => $value) {
            DB::delete('jamesonread_favores', "uid='" . $uid . "' AND book_id='" . $value . "'");
        }
        break;
    case 'removestore':
        if (!$_G['uid'] || ($_G['uid'] != DB::result_first('SELECT uid FROM %t WHERE favore_id=%d', array('jamesonread_favores', $_GET['did'])))) {
            echo 'error';
            break;
        }
        if (C::t('#jameson_read#jamesonread_favores')->delete($_GET['did'])) {
            echo 'success';
        } else {
            echo 'error';
        }
        break;
    case 'updateorder':
        if ($_GET['tablename'] && is_array($_GET['neworder']) && $_GET['neworder']) {
            $field = $_GET['tablename'] == 'colums' ? 'zhangjie' : 'order_num';
            foreach ($_GET['neworder'] as $key => $value) {
                C::t('#jameson_read#jamesonread_' . trim($_GET['tablename']))->update($value, array($field => $key + 1));
            }
            C::t("#jameson_read#jamesonread_books")->clear_cache(array("bookinfo-".$_GET['book_id'] . '-0', "bookinfo-".$_GET['book_id'] . '-' . $_G['uid']));
            echo 'success';
        } else {
            echo 'error';
        }
        break;
    case 'toupiao':
        // 根据当前type获取票据信息
        $type     = intval($_GET['type']); //101 102 103 票据类型
        $piaoinfo = DB::fetch_first('SELECT * FROM %t WHERE type=%d', array('jamesonread_topics', $type));
        // 当前用户的积分情况
        $dqinfo  = C::t('common_member_count')->fetch($_G['uid']);
        $book_id = intval($_GET['book_id']);
        if ($dqinfo['extcredits' . $piaoinfo['image']] < $piaoinfo['url']) {
            echo 'buzu';
        } else {
            // 进行购买操作
            $res1 = updatemembercount($_G['uid'], array($piaoinfo['image'] => -$piaoinfo['url']), true, 'jtp', 0, lang('plugin/jameson_read', 'xiangzuozhetoupiao'), lang('plugin/jameson_read', 'xiangzuozhetoupiao'));
            if ($type == 101) {
                $field = 'yuepiao';
            } else if ($type == 102) {
                $field = 'tuijianpiao';
            } else {
                $field = 'cuigengpiao';
            }
            // 作者票数增加
            DB::query('UPDATE ' . DB::table('jamesonread_authors') . ' SET `' . $field . '`=`' . $field . "`+1 WHERE author_id='" . intval($_GET['author_id']) . "'");
            // 图书票数
            DB::query('UPDATE ' . DB::table('jamesonread_books') . ' SET `' . $field . '`=`' . $field . "`+1 WHERE book_id='" . intval($_GET['book_id']) . "'");

            // 当前用户添加购买记录
            C::t('#jameson_read#jamesonread_piao')->insert(array(
                'uid'      => $_G['uid'],
                'username' => $_G['member']['username'],
                'type'     => 1,
                'addtime'  => TIMESTAMP,
                'exid'     => $_G["setting"]["extcredits"][$piaoinfo['image']]['title'],
                'number'   => 1,
                'money'    => $piaoinfo['url'],
                'name'     => $piaoinfo['name'],
                'book_id'  => $_GET['book_id'],
            ));
            // 向购买者发送投票信息
            $book_name = DB::result_first('SELECT book_name FROM %t WHERE book_id=%d', array('jamesonread_books', $book_id));
            $sendbuy   = lang('plugin/jameson_read', 'nitouleyizhang')
            . $piaoinfo['name']
            . lang('plugin/jameson_read', 'gei')
            . '<a href="' . jamesonurl('book', $_GET['book_id'])
            . '">['
            . $book_name
            . ']</a>,'
            . lang('plugin/jameson_read', 'huafei')
                . $_G["setting"]["extcredits"][$piaoinfo['image']]['title']
                . $piaoinfo['url'];
            jameson_sendsms($_G['uid'], 0, '', $sendbuy, $_GET['book_id']);
            // 向打赏者发送消息
            $sendauthor = lang('plugin/jameson_read', 'nishoudaoyizhang')
            . $piaoinfo['name']
            . ','
            . lang('plugin/jameson_read', 'laizi')
            . $_G['member']['username']
            . lang('plugin/jameson_read', 'toupiao')
            . lang('plugin/jameson_read', 'gei')
            . '<a href="' . jamesonurl('book', $_GET['book_id'])
                . '">['
                . $book_name
                . ']</a>';
            jameson_sendsms($_GET['author_id'], 0, '', $sendauthor, $_GET['book_id']);
            C::t("#jameson_read#jamesonread_books")->clear_cache(array("bookinfo-".$book_id . '-0', "bookinfo-".$book_id . '-' . $_G['uid']));
            echo 'success';
        }
        break;
    case 'jiangliuid':
        echo (int) fxact($_G['uid'], intval($_GET['tid']), intval($_GET['book_id']), $_G['jameson_read']['jiangli'], $_G['jameson_read']['fxtrameid'], $_G['clientip']);
        break;
    case "upload":
        $book_id = intval($_GET['book_id']);
        $res     = 'error';
        if (isset($_FILES['imgname'])) {
            $upload = new discuz_upload();
            $upload->init($_FILES['imgname'], 'forum');
            if ($upload->is_image_ext($upload->fileext($_FILES['imgname']['name']))) {
                if ($upload->save()) {
                    C::t('#jameson_read#jamesonread_books')->update($book_id, array(
                        'image' => $upload->attach['attachment'],
                    ));
                    $res = './data/attachment/forum/' . $upload->attach['attachment'];
                }
            }
        }
        echo $res;
        break;
    case 'uploadbendi':
    // echo 'eee';
        $upload = new discuz_upload();
        $upload->init($_FILES['file'], 'forum');
        $res = array();
        $ext = $upload->fileext($_FILES['file']['name']);
        @dmkdir(DISCUZ_ROOT.'data/attachment/mbattach/'.$upload->attach['attachdir'],0777,true);
        if (in_array($ext,array('jpg','png','jpeg','gif','mp3','mp4'))) {
            $newname = 'data/attachment/mbattach/'.substr($upload->attach['attachment'], 0, strrpos($upload->attach['attachment'], '.')) . '.'.$ext;
            $upload->attach['target'] = DISCUZ_ROOT.$newname;
            if ($upload->save()) {
                $res = array('url'=>$_G['siteurl'].$newname);
            }else{
                $res = array('error'=>lang('plugin/jameson_read','weizhicuowu'));
            }
        }
        ob_clean();
        header('Content-Type: application/json; charset=utf-8');
        echo json_encode($res);exit;
    break;
    case "uploadzj":
        $book_id = intval($_GET['book_id']);
        $res     = array('errno' => 0, 'data' => array());
        if (isset($_FILES['images']['name'])) {
            foreach ($_FILES['images']['name'] as $key => $value) {
                $file             = array();
                $file['name']     = $value;
                $file['type']     = $_FILES['images']['type'][$key];
                $file['tmp_name'] = $_FILES['images']['tmp_name'][$key];
                $file['error']    = $_FILES['images']['error'][$key];
                $file['size']     = $_FILES['images']['size'][$key];
                $upload           = new discuz_upload();
                $upload->init($file, 'forum');
                if ($upload->is_image_ext($upload->fileext($file['name']))) {
                    if ($upload->save()) {
                        $res['data'][] = './data/attachment/forum/' . $upload->attach['attachment'];
                    }
                }
                unset($upload);
            }
            header('Content-Type: application/json; charset=utf-8');
            echo json_encode($res);
        } else {
            header('Content-Type: application/json; charset=utf-8');
            echo json_encode(array('errno' => 1, 'data' => array()));
        }
        break;
    case 'updatebooks':
        $book_id = intval($_GET['book_id']);
        $image = daddslashes($_GET['image']);
        C::t('#jameson_read#jamesonread_books')->update($book_id,array(
            'image'=>$image
        ));
    break;
    case 'noautobuy':
        dsetcookie('jamesonreadautobuy_'.$_G['uid'],null,-1000);
        echo 1;
    break;
}